if Assets == nil then
    Assets = {}
end


local LANGUAGE = "en"
if type(TUNING.__NPC_LANGUAGE) == "function" then
    LANGUAGE = TUNING.__NPC_LANGUAGE()
elseif type(TUNING.__NPC_LANGUAGE) == "string" then
    LANGUAGE = TUNING.__NPC_LANGUAGE
end
local sign_str_table = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_event_item_buyer"] or {}

----------------------------------------------------------------------------------------------------------------------------------------
------- 加载和创建个专属建造标签，并靠近才能使用。
------- 科技要单独设置添加
table.insert(Assets,      Asset("ATLAS", "images/quagmire_hud.xml")                         )     --  -- 载入贴图文件
table.insert(Assets,      Asset("IMAGE", "images/quagmire_hud.tex")                         )     --  -- 载入贴图文件
RegisterInventoryItemAtlas("images/quagmire_hud.xml", "images/quagmire_hud.tex")                -- 注册贴图文件【必须要做】

--------- 添加活动tag给指定的 prefab，不能大写。 制作栏 左上角 的图标 和 鼠标过去的文字
PROTOTYPER_DEFS["monster_npc_pigman_intermediary_businessman"] = {      ----- 必须是 prefab 的名字
    icon_atlas = "images/quagmire_hud.xml", 
    icon_image = "tab_quagmire_swampigelder.tex",	
    is_crafting_station = true,
    action_str = "TRADE",   --- 相关参数 参考 recipes.lua
    filter_text = sign_str_table.filter_text  or "666666666"
} -- 正常
----------------------------------------------------------------------------------------
RECIPETABS[string.upper("intermediary_pigman_shop")] = { 
    str = string.upper("intermediary_pigman_shop"),
    sort = 999, 
    icon = "tab_quagmire_swampigelder.tex", 
    icon_atlas = "images/quagmire_hud.xml", 
    crafting_station = true,
    shop = true
}
----------------------------------------------------------------------------------------
local TechTree = require("techtree")
TechTree.Create_____npc_old = TechTree.Create
TechTree.Create = function(t)
	t = t or {}
	for i, v in ipairs(TechTree.AVAILABLE_TECH) do
	    t[v] = t[v] or 0
	end
	return t
end

table.insert(TechTree.AVAILABLE_TECH,string.upper("intermediary_pigman_shop")) ---- 添加到科技树
table.insert(TechTree.BONUS_TECH,string.upper("intermediary_pigman_shop")) ---- 有奖励的科技树

-------------------- 科技参数
TECH.NONE[string.upper("intermediary_pigman_shop")] = 0
TECH[string.upper("intermediary_pigman_shop_one")] = {
    [string.upper("intermediary_pigman_shop")] = 1,
}
for k,v in pairs(TUNING.PROTOTYPER_TREES) do    ---------- 给其他标签注入0参数
    v[string.upper("intermediary_pigman_shop")] = 0
end

TUNING.PROTOTYPER_TREES[string.upper("intermediary_pigman_shop")] = TechTree.Create({   ---- 靠近inst 的时候触发科技树标记位切换
    [string.upper("intermediary_pigman_shop")] = 1,
})

------- 给其他的添加科技类别 --- TECH.NONE  ---- 这个可能就是 builder_replica 造成崩溃的原因
for i, v in pairs(AllRecipes) do
	if v.level[string.upper("intermediary_pigman_shop")] == nil then
		v.level[string.upper("intermediary_pigman_shop")] = 0
	end
end
TechTree.Create = TechTree.Create_____npc_old
TechTree.Create_____npc_old = nil

----------------------------------------------------------------------------------------------------------------------------------------
local function Load_and_Register_Img(tex_name)
    table.insert(Assets,      Asset("ATLAS", "images/inventoryimages/"..tex_name..".xml")                         )     --  -- 载入贴图文件
    table.insert(Assets,      Asset("IMAGE", "images/inventoryimages/"..tex_name..".tex")                         )     --  -- 载入贴图文件
    RegisterInventoryItemAtlas("images/inventoryimages/"..tex_name.. ".xml", tex_name..".tex")  -- 注册贴图文件【必须要做】
end
Load_and_Register_Img("npc_item_tree_trade_station_kit")
Load_and_Register_Img("npc_item_walrus_camp")
Load_and_Register_Img("npc_item_sign_for_sale")
Load_and_Register_Img("npc_item_sign_for_sale_glass")
Load_and_Register_Img("npc_item_sign_for_sale_chesspiece")
Load_and_Register_Img("npc_item_sign_for_sale_veggie")
Load_and_Register_Img("npc_item_sign_for_sale_house")
Load_and_Register_Img("npc_item_sign_for_sale_sunkenchest")
Load_and_Register_Img("npc_item_sign_for_sale_shell_cluster")
Load_and_Register_Img("npc_item_sign_for_sale_birdcage")
Load_and_Register_Img("npc_item_dining_table")
Load_and_Register_Img("npc_item_goldnugget_coin")
Load_and_Register_Img("npc_item_no_discounts_amulet")
Load_and_Register_Img("npc_item_cards_station")

local items_in_shop_filer = {}  ---------- 用来清除多余的，不是本模组的东西
local function Add_Recipe_To_Shop_Filter(_table)
    -- _table = {
    --     prefab = "log",
    --     NAME = "木头",
    --     RECIPE_DESC = "9999++++",
    --     Ingredients = { Ingredient("goldnugget", 100) },
    --     configs = {
    --         atlas = "images/inventoryimages/npc_item_goldnugget_coin.xml",
    --         image = "npc_item_goldnugget_coin.tex",
    --     }
    -- }
    if _table.NAME then    -- -- 制造栏里展示的名字
        GLOBAL.STRINGS.NAMES[string.upper(_table.prefab)] = _table.NAME
    end
    if _table.RECIPE_DESC then  -- --  制造栏里展示的说明
        STRINGS.RECIPE_DESC[string.upper(_table.prefab)] = _table.RECIPE_DESC
    end
    AddRecipeToFilter(_table.prefab,string.upper("intermediary_pigman_shop"))   --- 添加到指定栏目
    AddRecipe2(
        _table.prefab,            --  --  inst.prefab  实体名字
        _table.Ingredients or {}, 
        TECH[string.upper("intermediary_pigman_shop_one")], --- TECH.NONE
        {
            nounlock=true,no_deconstruction=true,
            -- min_spacing = 1,
            builder_tag = "npc_tag_no_green_amulet",    --------- -- 【builder_tag】只给指定tag的角色能制造这件物品，角色添加/移除 tag 都能立马解锁/隐藏该物品
            sg_state = "give",
            actionstr = "CARNIVAL_HOSTSHOP",
            atlas = _table.configs.atlas,
            image = _table.configs.image,
            placer = _table.configs.placer,
        },
        {string.upper("intermediary_pigman_shop")}
    )
    RemoveRecipeFromFilter(_table.prefab,"MODS")

    table.insert(items_in_shop_filer,_table.prefab)
end
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
--- 黄金兑换金币    --- 旧的，暂时保留
    -- GLOBAL.STRINGS.NAMES[string.upper("npc_item_goldnugget_coin")] = sign_str_table.name_goldnugget_coin    -- -- 制造栏里展示的名字
    -- STRINGS.RECIPE_DESC[string.upper("npc_item_goldnugget_coin")] = sign_str_table.recipe_desc_goldnugget_coin  -- --  制造栏里展示的说明
    -- AddRecipeToFilter("npc_item_goldnugget_coin",string.upper("intermediary_pigman_shop")) 
    -- AddRecipe2(
    --     "npc_item_goldnugget_coin",            --  --  inst.prefab  实体名字
    --     {Ingredient("goldnugget", 100)}, 
    --     TECH[string.upper("intermediary_pigman_shop_one")], --- TECH.NONE
    --     {
    --         nounlock=true,no_deconstruction=true,
    --         builder_tag = "npc_tag_no_green_amulet",    --------- -- 【builder_tag】只给指定tag的角色能制造这件物品，角色添加/移除 tag 都能立马解锁/隐藏该物品
    --         sg_state = "give",
    --         actionstr = "CARNIVAL_HOSTSHOP",
    --         atlas = "images/inventoryimages/npc_item_goldnugget_coin.xml",
    --         image = "npc_item_goldnugget_coin.tex",
    --     },
    --     {string.upper("intermediary_pigman_shop")}
    -- )
    -- RemoveRecipeFromFilter("npc_item_goldnugget_coin","MODS")                       -- -- 在【模组物品】标签里移除这个。
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
--- 黄金兑换金币
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_goldnugget_coin",
    NAME = sign_str_table.name_goldnugget_coin,
    RECIPE_DESC = sign_str_table.recipe_desc_goldnugget_coin,
    Ingredients = {Ingredient("goldnugget", 100)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_goldnugget_coin.xml",
        image = "npc_item_goldnugget_coin.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
--- 金币兑换黄金
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_goldnugget_coin_exchange",
    NAME = sign_str_table.name_goldnugget_coin_exchange ,
    RECIPE_DESC = sign_str_table.recipe_desc_goldnugget_coin_exchange,
    Ingredients = {Ingredient("npc_item_goldnugget_coin", 1)} ,
    configs = {
        atlas = GetInventoryItemAtlas("goldnugget.tex") ,
        image = "goldnugget.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 雕像用的标记木牌
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_create_sign_chesspiece",
    NAME = sign_str_table.name_chesspiece ,
    RECIPE_DESC = sign_str_table.recipe_desc_chesspiece,
    Ingredients = {Ingredient("goldnugget", 1)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_sign_for_sale_chesspiece.xml",
        image = "npc_item_sign_for_sale_chesspiece.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 玻璃用的标记木牌
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_create_sign_glass",
    NAME = sign_str_table.name_glass ,
    RECIPE_DESC = sign_str_table.recipe_desc_glass,
    Ingredients = {Ingredient("goldnugget", 5)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_sign_for_sale_glass.xml",
        image = "npc_item_sign_for_sale_glass.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 巨大植物用的的标记木牌
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_create_sign_veggie",
    NAME = sign_str_table.name_veggie ,
    RECIPE_DESC = sign_str_table.recipe_desc_veggie,
    Ingredients = {Ingredient("goldnugget", 10)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_sign_for_sale_veggie.xml",
        image = "npc_item_sign_for_sale_veggie.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 房子用的的标记木牌
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_create_sign_house",
    NAME = sign_str_table.name_house ,
    RECIPE_DESC = sign_str_table.recipe_desc_house,
    Ingredients = {Ingredient("goldnugget", 8)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_sign_for_sale_house.xml",
        image = "npc_item_sign_for_sale_house.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 沉底宝箱用的的标记木牌
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_create_sign_sunkenchest",
    NAME = sign_str_table.name_sunkenchest ,
    RECIPE_DESC = sign_str_table.recipe_desc_sunkenchest,
    Ingredients = {Ingredient("goldnugget", 100)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_sign_for_sale_sunkenchest.xml",
        image = "npc_item_sign_for_sale_sunkenchest.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 贝壳堆用的的标记木牌
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_create_sign_shell_cluster",
    NAME = sign_str_table.name_shell_cluster ,
    RECIPE_DESC = sign_str_table.recipe_desc_shell_cluster,
    Ingredients = {Ingredient("goldnugget", 1)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_sign_for_sale_shell_cluster.xml",
        image = "npc_item_sign_for_sale_shell_cluster.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 鸟笼用的的标记木牌
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_create_sign_birdcage",
    NAME = sign_str_table.name_birdcage ,
    RECIPE_DESC = sign_str_table.recipe_desc_birdcage,
    Ingredients = {Ingredient("goldnugget", 1)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_sign_for_sale_birdcage.xml",
        image = "npc_item_sign_for_sale_birdcage.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 餐桌订单
-------------------------------------------------------------------------------------------------------------------------------------------------
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_dining_table",
    NAME = sign_str_table.name_dining_table ,
    RECIPE_DESC = sign_str_table.recipe_desc_dining_table,
    Ingredients = {Ingredient("goldnugget", 5)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_dining_table.xml",
        image = "npc_item_dining_table.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 特制高礼帽
-------------------------------------------------------------------------------------------------------------------------------------------------
local tophat_table = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_item_magic_tophat"] or {}
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_magic_tophat",
    NAME = tophat_table.name ,
    RECIPE_DESC =  tophat_table.recipe_desc,
    Ingredients = {Ingredient("npc_item_goldnugget_coin", 5)} ,
    configs = {
        atlas = GetInventoryItemAtlas("tophat.tex"),
        image = "tophat.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 传送指南针
-------------------------------------------------------------------------------------------------------------------------------------------------
local transform_compass_table = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_item_transform_compass"] or {}
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_transform_compass",
    NAME = transform_compass_table.name ,
    RECIPE_DESC =  transform_compass_table.inspect_str,
    Ingredients = {Ingredient("npc_item_goldnugget_coin", 1)} ,
    configs = {
        atlas = GetInventoryItemAtlas("compass.tex"),
        image = "compass.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
-- --- 乌鸦商队栖息树
-- -------------------------------------------------------------------------------------------------------------------------------------------------
local STR_TABLE_npc_item_tree_trade_station_kit = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_item_tree_trade_station"] or {}
local npc_item_tree_trade_station_cost = 1
if TUNING.NPC_CONFIG.REWARDS_LESS  == true then
    npc_item_tree_trade_station_cost = 2
end
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_tree_trade_station_kit",
    NAME = STR_TABLE_npc_item_tree_trade_station_kit.Production_Column_name ,
    RECIPE_DESC =  STR_TABLE_npc_item_tree_trade_station_kit.Production_Column_desc,
    Ingredients = {Ingredient("npc_item_goldnugget_coin", npc_item_tree_trade_station_cost),Ingredient("goldnugget", npc_item_tree_trade_station_cost*25)} ,
    configs = {
        atlas = "images/inventoryimages/npc_item_tree_trade_station_kit.xml",
        image = "npc_item_tree_trade_station_kit.tex",
    },
})
---------------------------------------------------------------------------------------------------------------------------------------------------
----- 海象人卡牌站
---------------------------------------------------------------------------------------------------------------------------------------------------
local STR_TABLE_npc_item_cards_station = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_item_cards_station"] or {}
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_cards_station_kit",
    NAME = STR_TABLE_npc_item_cards_station.name ,
    RECIPE_DESC =  STR_TABLE_npc_item_cards_station.recipe_desc,
    Ingredients = {Ingredient("npc_item_goldnugget_coin", 6)},
    configs = {
        atlas = "images/inventoryimages/npc_item_cards_station.xml",
        image = "npc_item_cards_station.tex",
        -- placer = "npc_item_cards_station_placer",
    },
})
---------------------------------------------------------------------------------------------------------------------------------------------------
----- 彩虹号角
---------------------------------------------------------------------------------------------------------------------------------------------------
local STR_TABLE_npc_item_rainbow_horn = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_item_rainbow_horn"] or {}
Add_Recipe_To_Shop_Filter({
    prefab = "npc_item_rainbow_horn",
    NAME = STR_TABLE_npc_item_rainbow_horn.name ,
    RECIPE_DESC =  STR_TABLE_npc_item_rainbow_horn.recipe_desc,
    Ingredients = {Ingredient("npc_item_goldnugget_coin", 2)},
    configs = {
        atlas = GetInventoryItemAtlas("horn.tex"),
        image = "horn.tex",
    },
})
-------------------------------------------------------------------------------------------------------------------------------------------------
--- 清洁扫把
if TUNING.NPC_MOD_TEST_DEBUG == true then	
    Add_Recipe_To_Shop_Filter({
        prefab = "reskin_tool",
        Ingredients = {Ingredient("goldnugget", 1)} ,
        configs = {
        },
    })
end
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------------------------------------------
------ 佩戴绿色护符的警告
-------------------------------------------------------------------------------------------------------------------------------------------------
local no_discounts_amulet_table = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_item_no_discounts_amulet"] or {}
GLOBAL.STRINGS.NAMES[string.upper("npc_item_no_discounts_amulet")] = no_discounts_amulet_table.name    -- -- 制造栏里展示的名字
STRINGS.RECIPE_DESC[string.upper("npc_item_no_discounts_amulet")] = no_discounts_amulet_table.recipe_desc  -- --  制造栏里展示的说明
AddRecipeToFilter("npc_item_no_discounts_amulet",string.upper("intermediary_pigman_shop")) 
AddRecipe2(
    "npc_item_no_discounts_amulet",            --  --  inst.prefab  实体名字
    {Ingredient("twigs", 10)}, 
    TECH[string.upper("intermediary_pigman_shop_one")], --- TECH.NONE
    {
        nounlock=true, no_deconstruction=true,
        builder_tag = "npc_tag_has_green_amulet",    --------- -- 【builder_tag】只给指定tag的角色能制造这件物品，角色添加/移除 tag 都能立马解锁/隐藏该物品
        sg_state = "give",
        actionstr = "CARNIVAL_HOSTSHOP",
        atlas = GetInventoryItemAtlas("npc_item_no_discounts_amulet.tex"),
        image = "npc_item_no_discounts_amulet.tex",
    },
    {string.upper("intermediary_pigman_shop")}
)
RemoveRecipeFromFilter("npc_item_no_discounts_amulet","MODS")                       -- -- 在【模组物品】标签里移除这个。

---------------------------------------------------------------------------------------------------------------------------------------------------
----- 海象人房子
---------------------------------------------------------------------------------------------------------------------------------------------------
local STR_TABLE_npc_item_walrus_camp = TUNING.NPC_CHAT_TABLE[LANGUAGE] ["npc_item_walrus_camp"] or {}
GLOBAL.STRINGS.NAMES[string.upper("npc_item_walrus_camp")] = STR_TABLE_npc_item_walrus_camp.name    -- -- 制造栏里展示的名字
STRINGS.RECIPE_DESC[string.upper("npc_item_walrus_camp")] = STR_TABLE_npc_item_walrus_camp.recipe_desc  -- --  制造栏里展示的说明
AddRecipeToFilter("npc_item_walrus_camp","STRUCTURES")        --- --- 在类别里注册物品名字
AddRecipe2(
    "npc_item_walrus_camp",            --  --  inst.prefab  实体名字
    {Ingredient("walrus_tusk", 100),Ingredient("npc_item_goldnugget_coin", 2)}, -- 角色三维资源必须是5的倍数
    TECH.SCIENCE_TWO,       -- SCIENCE_TWO
    {
        builder_tag = "npc_tag_no_green_amulet",
        placer = "npc_item_walrus_camp_placer",
        atlas = "images/inventoryimages/npc_item_walrus_camp.xml",
        image = "npc_item_walrus_camp.tex",
    },
    {"STRUCTURES"}       -- -- 在哪些制造分栏出现，可以多个 -- "CHARACTER"
)
RemoveRecipeFromFilter("npc_item_walrus_camp","MODS")                       -- -- 在【模组物品】标签里移除这个。
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
---- 系统底层级别的BUG，必须在后面弄个 TECH.NONE 的东西，不然会在载入时候崩溃，不知道为什么,不打算深入探究。直接末尾加个隐藏的制造项目就行了
---------------------------------------------------------------------------------------------------------------------------------------------------
------------ 用来避免崩溃的额外插入项目，TECH.NONE 必须在最后，不然这种暴力插入 会导致崩溃
        ------------ 废弃的物品转换，用个特殊tag隐藏
        AddRecipeToFilter("npc_item_lucky_goldnugget_exchange","MAGIC")        --- --- 在类别里注册物品名字
        AddRecipe2(
            "npc_item_lucky_goldnugget_exchange",            --  --  inst.prefab  实体名字
            {Ingredient("walrus_tusk", 100),Ingredient("npc_item_goldnugget_coin", 2)}, -- 角色三维资源必须是5的倍数
            TECH.NONE,
            {
                builder_tag = "npc_tag_no_green_amulet99999999",
                placer = "npc_item_walrus_camp_placer",
                atlas = "images/inventoryimages/npc_item_walrus_camp.xml",
                image = "npc_item_walrus_camp.tex",
            },
            {"MAGIC"}       -- -- 在哪些制造分栏出现，可以多个 -- "CHARACTER"
        )
        RemoveRecipeFromFilter("npc_item_lucky_goldnugget_exchange","MODS")                       -- -- 在【模组物品】标签里移除这个。

---------------------------------------------------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
------------ 暴力添加栏目会造成 builder_replica 进入 nil 参数，
------------ 懒得去找为什么了，直接屏蔽nil 参数进入就行了，
------------ 理论上已经修复了，但是为了保险起见，保持hook
-------------------------------------------------------------------------------------------------------------------------------------------------
local com_builder_replica = _G.require "components/builder_replica"
com_builder_replica.KnowsRecipe_old__npc_mod = com_builder_replica.KnowsRecipe
com_builder_replica.KnowsRecipe = function(self,recipe,ignore_tempbonus)
    if recipe == nil then
        print(" ++++++++++++++++++++++++++ com_builder_replica error : recipe is nil")
        return false
    end 
    local crash_flag ,ret = pcall(function()
        local ret = {self:KnowsRecipe_old__npc_mod(recipe,ignore_tempbonus)}
        return ret
    end)
    if crash_flag == true then    ----- 
        return unpack(ret)
    else                          ----- crash happend
        return false
    end
end
---------------------------------------------------------------------------------------------------------------------------------------------------
-------- 为了更保险，连builder组件一起改了
local com_builder = _G.require "components/builder"
com_builder.KnowsRecipe_old__npc_mod = com_builder.KnowsRecipe
com_builder.KnowsRecipe = function(self,recipe,ignore_tempbonus)
    if recipe == nil then
        print(" ++++++++++++++++++++++++++ com_builder error : recipe is nil")
        return false
    end 
    local flag ,ret = pcall(function()
        local ret = {self:KnowsRecipe_old__npc_mod(recipe,ignore_tempbonus)}
        return ret
    end)
    if flag == true then
        return unpack(ret)
    else
        return false
    end
end
---------------------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------------------
